package org.example;

import cn.hutool.core.io.FileUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.lang.NonNull;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, FlywayAutoConfiguration.class})
@MapperScan("org.example.mapper")
@EnableScheduling
public class MainApplication {
    public static void main(String[] args) {
       String s= "尊敬的张三";
        System.out.println(s.substring(0,3));
        SpringApplication.run(MainApplication.class, args);

        /*File file = FileUtil.file("D:\\Users\\Desktop\\aa\\aaa\\aa\\555\\1.txt");
        delete(file);*/

    }

    public static void delete(File file) {
        if (FileUtil.isFile(file)) {
            File parent = file.getParentFile();
            FileUtil.del(file);
            deleteDir(parent);
        }
    }

    private static void deleteDir(File parent) {
        if (FileUtil.isEmpty(parent)) {
            if (FileUtil.del(parent)) {
                deleteDir(parent.getParentFile());
            }
        }
    }


    @Bean
    public BeanDefinitionRegistryPostProcessor beanDefinitionRegistryPostProcessor() {
        return new BeanDefinitionRegistryPostProcessor() {
            @Override
            public void postProcessBeanDefinitionRegistry(@NonNull BeanDefinitionRegistry registry) throws BeansException {
                // 在这里可以添加、修改或移除Bean定义
                // 示例：移除一个名为"exampleBean"的Bean定义
                if (registry.containsBeanDefinition("okHttpClient")) {
                    System.out.println("aaa");
                }
            }

            @Override
            public void postProcessBeanFactory(@NonNull ConfigurableListableBeanFactory beanFactory) throws BeansException {
                // 这个方法可以不用实现，因为我们不需要修改BeanFactory
            }
        };
    }
}
